﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using KZ.Lottery.Entities;
using KZ.Lottery.Report;
using KZ.Lottery.Resources;
using KZ.Utilities;

namespace KZ.Lottery
{
    public partial class FrmPreview : Form
    {
        public FrmPreview()
        {
            InitializeComponent();
        }

        private void FrmPreview_Load(object sender, EventArgs e)
        {
            switch (ReportType)
            {
                case "ReportByRule":
                    LoadReportByRule();
                    break;
                case "ReportByChannel":
                    LoadReportByChannel();
                    break;
            }
        }

        private void LoadReportByRule()
        {
            RptByRule rptByRule = new RptByRule();
            rptByRule.SetDataSource(RuleReportList);

            if (FromStart)
            {
                rptByRule.SetParameterValue(rptByRule.Parameter_lblReportTitle.ParameterFieldName,
                    KZ_Resource.Report);
            }
            else
            {
                rptByRule.SetParameterValue(rptByRule.Parameter_lblReportTitle.ParameterFieldName,
                    String.Format(KZ_Resource.ReportFromTo, From.ToShortPattern(Global.Culture), To.ToShortPattern(Global.Culture)));
            }

            crystalReportViewer1.ReportSource = rptByRule;
        }

        private void LoadReportByChannel()
        {
            RptByChannel rptByChannel = new RptByChannel();
            rptByChannel.SetDataSource(RuleReportList);

            if (FromStart)
            {
                rptByChannel.SetParameterValue(rptByChannel.Parameter_lblReportTitle.ParameterFieldName,
                    KZ_Resource.Report);
            }
            else
            {
                rptByChannel.SetParameterValue(rptByChannel.Parameter_lblReportTitle.ParameterFieldName,
                    String.Format(KZ_Resource.ReportFromTo, From.ToShortPattern(Global.Culture), To.ToShortPattern(Global.Culture)));
            }

            crystalReportViewer1.ReportSource = rptByChannel;
        }

        public List<RuleReport> RuleReportList { get; set; }

        public string ReportType { get; set; }

        public DateTime From { get; set; }

        public DateTime To { get; set; }

        public bool FromStart { get; set; }
    }
}